<template>
  <div class="main">
    <div class="top">
      <div class="userIcon">
        <img
          v-if="!commentData.user.head_img"
          src="../../assets/img/男头像.png"
          alt=""
        />
        <img
          v-else
          :src="$axios.defaults.baseURL + commentData.user.head_img"
          alt=""
        />
      </div>
      <div class="userInfo">
        <div class="name">{{ commentData.user.nickname }}</div>
        <div class="date">3小时前</div>
      </div>
      <div class="reply" @click="sendComment">回复</div>
    </div>
    <!-- 父评论 -->
    <parent :parentComment="commentData.parent" v-if="commentData.parent" />

    <!-- 主评论 -->
    <div class="mainCom" v-if="commentData.content">
      {{ commentData.content }}
    </div>
    <div class="mainCom" v-else>评论为空</div>
  </div>
</template>

<script>
import parent from "./parent.vue";
import eventBus from "../../utils/eventBus";
export default {
  components: { parent },
  props: ["commentData"],
  methods: {
    sendComment() {
      eventBus.$emit("sendMsg", this.commentData.id);
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  border-bottom: 1px solid #ccc;
  padding: 10 /360 * 100vw 20 /360 * 100vw;
  .top {
    margin-bottom: 10 /360 * 100vw;

    display: flex;
    align-items: center;
    .userInfo {
      margin-left: 10 /360 * 100vw;
      flex-grow: 1;
      .date {
        font-size: 12 /360 * 100vw;
        color: #888;
      }
    }
    .userIcon {
      img {
        width: 40 /360 * 100vw;
        height: 40 /360 * 100vw;
        object-fit: cover;
        border-radius: 50%;
      }
    }
  }
  .mainCom {
    margin-top: 15 /360 * 100vw;
    font-size: 18 /360 * 100vw;
    color: rgb(34, 30, 30);
  }
}
</style>